#include "fonts.h"
#include "display.h"


prog_uint8_t font[FONT_SIZE][6] =
{
   {  /*  ' '   */ 3, 0x00, 0x00, 0x00, 0x00, 0x00 },
   {  /*  '!'   */ 2, 0x17, 0x17, 0x00, 0x00, 0x00 },
   {  /*  '"'   */ 3, 0x03, 0x00, 0x03, 0x00, 0x00 },
   {  /*  '#'   */ 5, 0x0a, 0x1f, 0x0a, 0x1f, 0x0a },
   {  /*  '$'   */ 5, 0x02, 0x15, 0x1f, 0x15, 0x08 },
   {  /*  '%'   */ 5, 0x13, 0x0b, 0x04, 0x1a, 0x19 },
   {  /*  '&->8'*/ 3, 0x1f, 0x15, 0x1f, 0x00, 0x00 },
   {  /*  '''   */ 1, 0x03, 0x00, 0x00, 0x00, 0x00 },
   {  /*  '('   */ 2, 0x0e, 0x11, 0x11, 0x00, 0x00 },
   {  /*  ')'   */ 2, 0x11, 0x11, 0x0e, 0x00, 0x00 },   
   {  /*  '*'   */ 5, 0x04, 0x0e, 0x04, 0x0e, 0x04 },   
   {  /*  '+'   */ 3, 0x04, 0x0e, 0x04, 0x00, 0x00 },   
   {  /*  ','   */ 2, 0x14, 0x0c, 0x00, 0x00, 0x00 },   
   {  /*  '-'   */ 3, 0x04, 0x04, 0x04, 0x00, 0x00 },   
   {  /*  '.'   */ 2, 0x18, 0x18, 0x00, 0x00, 0x00 },
   {  /*  '/'   */ 5, 0x10, 0x08, 0x04, 0x02, 0x01 },
   {  /*  '0'   */ 3, 0x1f, 0x11, 0x1f, 0x00, 0x00 },
   {  /*  '1'   */ 3, 0x11, 0x1f, 0x10, 0x00, 0x00 },
   {  /*  '2'   */ 3, 0x1d, 0x15, 0x17, 0x00, 0x00 },
   {  /*  '3'   */ 3, 0x15, 0x15, 0x1f, 0x00, 0x00 },
   {  /*  '4'   */ 3, 0x07, 0x04, 0x1f, 0x00, 0x00 },
   {  /*  '5'   */ 3, 0x17, 0x15, 0x1d, 0x00, 0x00 },
   {  /*  '6'   */ 3, 0x1f, 0x15, 0x1d, 0x00, 0x00 },
   {  /*  '7'   */ 3, 0x01, 0x01, 0x1f, 0x00, 0x00 },
   {  /*  '8'   */ 3, 0x1f, 0x15, 0x1f, 0x00, 0x00 },
   {  /*  '9'   */ 3, 0x07, 0x05, 0x1f, 0x00, 0x00 },
   {  /*  ':'   */ 1, 0x0a, 0x00, 0x00, 0x00, 0x00 },
   {  /*  ';->: */ 1, 0x0a, 0x00, 0x00, 0x00, 0x00 },
   {  /*  '<'   */ 3, 0x04, 0x0a, 0x11, 0x00, 0x00 },
   {  /*  '='   */ 4, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a },   
   {  /*  '>'   */ 3, 0x11, 0x0a, 0x04, 0x00, 0x00 },
   {  /*  '?'   */ 5, 0x02, 0x01, 0x01, 0x15, 0x02 },
   {  /*  '@'   */ 5, 0x0e, 0x11, 0x17, 0x17, 0x06 },
   {  /*  'A'   */ 3, 0x1e, 0x05, 0x1e, 0x00, 0x00 },
   {  /*  'B'   */ 3, 0x1f, 0x15, 0x0a, 0x00, 0x00 },
   {  /*  'C'   */ 3, 0x0e, 0x11, 0x11, 0x00, 0x00 },
   {  /*  'D'   */ 3, 0x1f, 0x11, 0x0e, 0x00, 0x00 },
   {  /*  'E'   */ 3, 0x1f, 0x15, 0x15, 0x00, 0x00 },
   {  /*  'F'   */ 3, 0x1f, 0x05, 0x05, 0x00, 0x00 },
   {  /*  'G'   */ 5, 0x0e, 0x11, 0x15, 0x1d, 0x04 },
   {  /*  'H'   */ 3, 0x1f, 0x04, 0x1f, 0x00, 0x00 },
   {  /*  'I'   */ 3, 0x11, 0x1f, 0x11, 0x00, 0x00 },
   {  /*  'J'   */ 3, 0x19, 0x10, 0x1e, 0x00, 0x00 },
   {  /*  'K'   */ 4, 0x1f, 0x04, 0x0a, 0x11, 0x00 },
   {  /*  'L'   */ 3, 0x1f, 0x10, 0x10, 0x00, 0x00 },
   {  /*  'M'   */ 5, 0x1f, 0x02, 0x04, 0x02, 0x1f },
   {  /*  'N'   */ 5, 0x1f, 0x02, 0x04, 0x08, 0x1f },
   {  /*  'O'   */ 3, 0x1f, 0x11, 0x1f, 0x00, 0x00 },
   {  /*  'P'   */ 3, 0x1f, 0x05, 0x07, 0x00, 0x00 },
   {  /*  'Q'   */ 5, 0x0e, 0x11, 0x15, 0x09, 0x16 },
   {  /*  'R'   */ 4, 0x1f, 0x05, 0x0d, 0x12, 0x00 },
   {  /*  'S'   */ 3, 0x12, 0x15, 0x09, 0x00, 0x00 },
   {  /*  'T'   */ 3, 0x01, 0x1f, 0x01, 0x00, 0x00 },
   {  /*  'U'   */ 3, 0x1f, 0x10, 0x1f, 0x00, 0x00 },
   {  /*  'V'   */ 5, 0x07, 0x08, 0x10, 0x08, 0x07 },
   {  /*  'W'   */ 5, 0x0f, 0x10, 0x0c, 0x10, 0x0f },
   {  /*  'X'   */ 5, 0x11, 0x0a, 0x04, 0x0a, 0x11 },
   {  /*  'Y'   */ 3, 0x07, 0x1c, 0x07, 0x00, 0x00 },
   {  /*  'Z'   */ 3, 0x19, 0x15, 0x13, 0x00, 0x00 },
   {  /*  '['   */ 3, 0x1f, 0x11, 0x11, 0x00, 0x00 },
   {  /*  '\'   */ 5, 0x01, 0x02, 0x04, 0x08, 0x10 },
   {  /*  ']'   */ 3, 0x11, 0x11, 0x1f, 0x00, 0x00 },
   {  /*  '^'   */ 5, 0x04, 0x02, 0x01, 0x02, 0x04 },
   {  /*  '_'   */ 4, 0x10, 0x10, 0x10, 0x10, 0x00 }
};



void LedPrint(uint8_t *c, int8_t x, int8_t y)
{
/* Print string on the screen, no scroll, text outside of the screen will not be printed
   c: pointer to the regular string to be printed
   x,y position of the first character from the screen (left lower corner of the first character)
*/
  uint8_t i, fn, FontWidth;
  uint16_t 	ResetColV;
  uint8_t *text;

  ResetColV = ResetCol << (FONTHEIGHT-y);  // Calculate a mask for clearing place for the new charactr's column
  for (text=c; (*text); text++)			   // for all characters in in the string to be printed
  {
	fn = *text - FirstASCIICharacter;	   // get the index of the character in the ASCII table from fonts.h
	FontWidth = pgm_read_byte(&font[fn][FONTWIDTHIDX])+FONTDEFIDX;  // read the fonth width based on the font 'sindex
	for (i=FONTDEFIDX ; i < FontWidth ; i++)						// Draw font's columns
	{
        if ((x >= 0) && (x < SWIDTH))								// Draw only on the screen, fix me: do not process the text any longer
		{
		  gLEDs[x] &= ~ResetColV;									// clear the place for the font's column
		  gLEDs[x] |= pgm_read_byte(&font[fn][i]) << (FONTHEIGHT-y); // draw one font's column data
		}
		x++;														// next column on the screen
	}
	x++;  															// after one character make one column empty  
  }
}
